package com.example.office.util.pubTopic;

import org.zeromq.ZMQ;

/**
 * @ Author     ：jujh
 * @ Date       ：Created in 14:36 2018/12/24
 * @ Description：发布
 */
public class ZMQ_PUB {

    public static void main(String[] args) throws InterruptedException {
        //准备上下文和套接字
        ZMQ.Context context = ZMQ.context(1);
        ZMQ.Socket publisher = context.socket(ZMQ.PUB);
        publisher.bind("tcp://*:5555");
        //发布100条消息
        Thread.sleep(1000);
        for (int i = 0; i < 100; i++) {
            String str = "admin " + i;
            publisher.send(str.getBytes(), ZMQ.NOBLOCK);
            System.out.println("pub msg: " + str);
            Thread.sleep(1000);
        }
        //关闭套接字和上下文
        publisher.close();
        context.term();
    }
}
